<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <!-- <a-button @click="handleAdd" type="primary" icon="plus" v-has="'serverInfo:add'">新增</a-button> -->
        <!-- <a-button type="primary" icon="download" @click="handleExportXls('服务表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"
              ><a-icon type="delete" v-has="'serverInfo:delete'" />删除</a-menu-item
            >
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper" style="display: flex; justify-content: end">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="城市服务商" style="margin-right: 10px" v-has="'xhdjServiceProjectDataReport:select'">
            <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
          </a-form-item>
          <a-form-item label="标题" style="margin-right: 10px;">
            <a-input placeholder="请输入标题" v-model="queryParam.title"></a-input>
          </a-form-item>
          <a-form-item label="开始时间" style="margin-right: 10px;" >
            <a-date-picker v-model="queryParam.startTime" @change="startChange" :valueFormat="'YYYY-MM-DD'" />
          </a-form-item>
          <a-form-item label="结束时间" style="margin-right: 10px;">
            <a-date-picker v-model="queryParam.endTime" @change="endChange"  :valueFormat="'YYYY-MM-DD'" :disabled-date="disabledDate" />
          </a-form-item>
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
          </span>
        </a-form>
      </div>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="price"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- 状态回显 -->
        <template slot="status" slot-scope="text, record">
          <div class="anty-img-wrap">
            {{ record.status == 1 ? '启用' : '禁用' }}
          </div>
        </template>
        <!-- 封面 图 -->
        <template slot="cover" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.cover)" />
          </div>
        </template>
        <!-- 介绍-->
        <template slot="introduce" slot-scope="text, record">
          <p v-html="record.introduce"></p>
        </template>
        <!-- 说明-->
        <template slot="serverExplain" slot-scope="text, record">
          <p v-html="record.serverExplain"></p>
        </template>
        <!-- 须知-->
        <template slot="notice" slot-scope="text, record">
          <p v-html="record.notice"></p>
        </template>
        <!-- 服务上架状态-->
        <template slot="putawayStatus" slot-scope="text, record">
          <div class="anty-img-wrap">
            {{ record.putawayStatus === 1 ? '上架' : '下架' }}
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'serverInfo:edit'">编辑</a>
          <a-divider type="vertical" v-has="'serverInfo:delete'" />
          <a-dropdown v-has="'serverInfo:delete'">
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getFileAccessHttpUrl } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import serveSelect from '@/components/serveSelect.vue'

export default {
  name: 'xhdjServiceProjectDataReport',
  mixins: [JeecgListMixin],
  components: {
    serveSelect,
  },
  data() {
    return {
      description: '服务项目数据报表',
      // 表头
      columns: [
        {
          title: '标题',
          align: 'center',
          dataIndex: 'title',
        },
        {
          title: '封面图',
          align: 'center',
          dataIndex: 'cover',
          scopedSlots: { customRender: 'cover' },
        },
        {
          title: '价格',
          align: 'center',
          dataIndex: 'price',
        },
        {
          title: '总的营业额',
          align: 'center',
          dataIndex: 'totalTurnover',
        },
        {
          title: '下单用户数',
          align: 'center',
          dataIndex: 'totalPayUserCount',
        },
        {
          title: '销量数量（不包含升级）',
          align: 'center',
          dataIndex: 'totalOrderNum',
        },
        {
          title: '总的退款金额',
          align: 'center',
          dataIndex: 'totalRefundAmout',
        },
        {
          title: '总退款订单数量',
          align: 'center',
          dataIndex: 'totalOutOrderNum',
        },
        {
          title: '升级销量  ',
          align: 'center',
          dataIndex: 'sjOrderNum',
        },
        {
          title: '加钟销售数量',
          align: 'center',
          dataIndex: 'speedOrderNum',
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      url: {
        list: '/xhdjServerInfo/queryPageStatisticsList',
        delete: '/xhdjServerInfo/delete',
        deleteBatch: '/deleteBatch',
        exportXlsUrl: 'xhdjServerInfo/exportXls',
        importExcelUrl: 'xhdjServerInfo/importExcel',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    startChange(value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    endChange(value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    selectClick(value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    disabledDate(time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-form {
  display: flex;
  justify-content: flex-end;
}
.ant-row {
  display: flex;
  justify-content: flex-end;
}
</style>
